
/*
'===============================================================================
'  Generated From - BLL_Component_Partial_Core.vbgen
'  
'  This object is partial class component representing a table in a database. It
'  contains core data access methods. Other partial classes should be used for 
'  implementing custom business logic. This class can be regenerated many times.
'  
'  Do not write custom business logic in this class as it will be overwritten 
'  next time the class is generated.
'
'  Version: 1.0
'  Date:	30/01/06
'  Summary: SelectOne, SelectAll, SelectAllWForeignKey, Insert, Update, Delete,
'  			DeleteAllWForeignKey, class for sorting.
'===============================================================================
*/
using System;
using System.ComponentModel;
using System.Data;
using System.Collections.Generic;

namespace PlacementManager
{
    [DataObjectAttribute]
	public partial class tblContactsComponent
    {
        
		/// <summary>
        /// Default constructor.
        /// </summary>
		public tblContactsComponent()
        {

        }
		
		/// <summary>
        /// Selects one record from the database table using the primary key.
        /// </summary>
        /// <returns>An object of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public tblContacts SelectOne(int ContactID)
        {  
			PlacementManager.DAL.tblContacts_DAL o = new PlacementManager.DAL.tblContacts_DAL();
			o.ContactID = ContactID;
			DataTable dt = o.SelectOne().Tables[0];
			
			if (dt.Rows.Count > 0)
            {
                DataRow row = dt.Rows[0];
				PlacementManager.tblContacts tblContactsToReturn = new PlacementManager.tblContacts((int)row["ContactID"], (string)row["Title"], (string)row["FirstName"], (string)row["LastName"], (string)row["JobTitle"], (string)row["StreetAddress"], (string)row["PostalAddress"], (string)row["TownCode"], (string)row["Phone"], (string)row["Mobile"], (string)row["Fax"], (string)row["Email"], (bool)row["NotCurrent"], (string)row["Qualification"], (string)row["Experience"], (int)row["AgencyID"], (string)row["Comments"], (string)row["OriginalCompany"], (bool)row["AgencyMailOuts"], (string)row["Response"], (bool)row["TakePlacement"], (bool)row["NSwReg"], (bool)row["VicReg"], (bool)row["DivI"], (bool)row["Psych"], (bool)row["Midwifery"], (int)row["Telephonenumber"], (string)row["RegNumber"]);
				return tblContactsToReturn;
			}
			else
			{
				PlacementManager.tblContacts tblContactsToReturnEmpty = new PlacementManager.tblContacts();
                return tblContactsToReturnEmpty;
			}
        }
		
		/// <summary>
        /// Selects all records from the database table.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<tblContacts> SelectAll(string sortExpression)
        {
            List<tblContacts> listtblContacts = new List<tblContacts>();
            PlacementManager.DAL.tblContacts_DAL o = new PlacementManager.DAL.tblContacts_DAL();

            DataSet ds = o.SelectAll();

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                listtblContacts.Add(new tblContacts((int)row["ContactID"], (string)row["Title"], (string)row["FirstName"], (string)row["LastName"], (string)row["JobTitle"], (string)row["StreetAddress"], (string)row["PostalAddress"], (string)row["TownCode"], (string)row["Phone"], (string)row["Mobile"], (string)row["Fax"], (string)row["Email"], (bool)row["NotCurrent"], (string)row["Qualification"], (string)row["Experience"], (int)row["AgencyID"], (string)row["Comments"], (string)row["OriginalCompany"], (bool)row["AgencyMailOuts"], (string)row["Response"], (bool)row["TakePlacement"], (bool)row["NSwReg"], (bool)row["VicReg"], (bool)row["DivI"], (bool)row["Psych"], (bool)row["Midwifery"], (int)row["Telephonenumber"], (string)row["RegNumber"]));
            }
			
			if (sortExpression == string.Empty)
            {
                sortExpression = "DateCreated desc";
            }

            listtblContacts.Sort(new tblContactsComparer(sortExpression));
            return listtblContacts;
        }
	

	}
	
	public class tblContactsComparer : IComparer<tblContacts>
    {
        private string _sortColumn;
        private bool _reverse;

        public tblContactsComparer(string sortExpression)
        {
            _reverse = sortExpression.ToLowerInvariant().EndsWith(" desc");
            if (_reverse)
            {
                _sortColumn = sortExpression.Substring(0, sortExpression.Length - 5);
            }
            else
            {
                _sortColumn = sortExpression;
            }
        }

        public int Compare(tblContacts a, tblContacts b)
        {
            int retVal = 0;
            switch (_sortColumn)
            {
				case "ContactID":
					retVal = String.Compare(a.ContactID.ToString(), b.ContactID.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "Title":
					retVal = String.Compare(a.Title.ToString(), b.Title.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "FirstName":
					retVal = String.Compare(a.FirstName.ToString(), b.FirstName.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "LastName":
					retVal = String.Compare(a.LastName.ToString(), b.LastName.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "JobTitle":
					retVal = String.Compare(a.JobTitle.ToString(), b.JobTitle.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "StreetAddress":
					retVal = String.Compare(a.StreetAddress.ToString(), b.StreetAddress.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "PostalAddress":
					retVal = String.Compare(a.PostalAddress.ToString(), b.PostalAddress.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "TownCode":
					retVal = String.Compare(a.TownCode.ToString(), b.TownCode.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "Phone":
					retVal = String.Compare(a.Phone.ToString(), b.Phone.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "Mobile":
					retVal = String.Compare(a.Mobile.ToString(), b.Mobile.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "Fax":
					retVal = String.Compare(a.Fax.ToString(), b.Fax.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "Email":
					retVal = String.Compare(a.Email.ToString(), b.Email.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "NotCurrent":
					retVal = String.Compare(a.NotCurrent.ToString(), b.NotCurrent.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "Qualification":
					retVal = String.Compare(a.Qualification.ToString(), b.Qualification.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "Experience":
					retVal = String.Compare(a.Experience.ToString(), b.Experience.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "AgencyID":
					retVal = String.Compare(a.AgencyID.ToString(), b.AgencyID.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "Comments":
					retVal = String.Compare(a.Comments.ToString(), b.Comments.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "OriginalCompany":
					retVal = String.Compare(a.OriginalCompany.ToString(), b.OriginalCompany.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "AgencyMailOuts":
					retVal = String.Compare(a.AgencyMailOuts.ToString(), b.AgencyMailOuts.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "Response":
					retVal = String.Compare(a.Response.ToString(), b.Response.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "TakePlacement":
					retVal = String.Compare(a.TakePlacement.ToString(), b.TakePlacement.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "NSwReg":
					retVal = String.Compare(a.NSwReg.ToString(), b.NSwReg.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "VicReg":
					retVal = String.Compare(a.VicReg.ToString(), b.VicReg.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DivI":
					retVal = String.Compare(a.DivI.ToString(), b.DivI.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "Psych":
					retVal = String.Compare(a.Psych.ToString(), b.Psych.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "Midwifery":
					retVal = String.Compare(a.Midwifery.ToString(), b.Midwifery.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "Telephonenumber":
					retVal = String.Compare(a.Telephonenumber.ToString(), b.Telephonenumber.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "RegNumber":
					retVal = String.Compare(a.RegNumber.ToString(), b.RegNumber.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;

            }
            return (retVal * (_reverse ? -1 : 1));
        }
    }
}
